package br.com.ravi.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public abstract class Cryptografia {
	
	public static String Criptografa(String texto) throws NoSuchAlgorithmException{	
		if (texto == null) {
			return null;			
		}
		
		MessageDigest md = MessageDigest.getInstance("MD5");		
		String s = texto;
		md.update( s.getBytes() );
		byte[] hash = md.digest();
		StringBuffer hexString = new StringBuffer();
		for (int i = 0; i < hash.length; i++) {
		     if ((0xff & hash[i]) < 0x10)
		          hexString.append( "0" + Integer.toHexString((0xFF & hash[i])));
		     else
		      hexString.append(Integer.toHexString(0xFF & hash[i]));
		}
		return hexString.toString();
		
	}
}